package com.practice.controller;

import com.practice.dto.MenuDTO;
import com.practice.form.LoginUser;
import com.practice.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @ClassName LoginController
 * @Description TODO
 * @Author KunxianLi
 * Date 2020/7/18 11:12
 * Version 1.0
 **/
@Controller
@RequestMapping("/admin")
public class LoginController {

    @Autowired
    private MenuService menuService;

    /**
     * @Author KunxianLi
     * @Description 登陆页面
     * @Date 2020/7/22 11:10
     * @Param []
     * @return java.lang.String
     **/
    @GetMapping("/login")
    public String toLogin(){

        return "login";
    }

    /**
     * @Author KunxianLi
     * @Description 登陆
     * @Date 2020/7/22 11:10
     * @Param [userForm, model]
     * @return java.lang.String
     **/
    @PostMapping("/login")
    public String login(LoginUser userForm, Model model) {

        List<MenuDTO> menus = menuService.getMenusByUserId(Long.valueOf(1));

        model.addAttribute("menus",menus);

        return "index";
    }

    @GetMapping("/logout")
    public String logout(Long userId){

        return "login";
    }


}
